<?php
/**
**名称:手机购物集子数据管理
**作用:手机购物各个集子的数据管理功能
**作者:张剑 swordphp@126.com
**创建日期:2013-07-17
**最后修改日期:2013-07-29
**/
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class jizi_data extends admin{
	public function __construct(){
		parent::__construct();
		pc_base::load_app_func('global');
		$this ->jihe_db = pc_base::load_model('jihe_model');
		$this ->item_db = pc_base::load_model('tmall_zhekou_model');
		$this ->tree = pc_base::load_sys_class('tree');
	}
	public function init(){
		$jid = isset($_POST['j_id'])?$_POST['j_id']:$_GET['j_id'];
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$infos = $this->item_db->listinfo(array('j_id'=>$jid,'is_display'=>1),'add_time DESC,`order_id`DESC',$page,'50');
		$pages = $this->item_db->pages;
		//var_dump($pages);
		$sort_tree = $this->get_sort_tree($jid);
		include $this->admin_tpl('item_list');
	}
	public function del(){
		$item_id = isset($_GET['item_id'])?$_GET['item_id']:'';
		if($item_id == ''){
			showmessage(L('operation_failure'));
		}else{
			$res = $this->item_db->update(array('is_display'=>0),array('id'=>$item_id));
			if($res){
				showmessage(L('operation_success'));
			}else{
				showmessage(L('operation_success'));
			}
		}
	}
	public function listorder() {
		if(isset($_POST['dosubmit'])) {
			foreach($_POST['order_id'] as $id => $order) {
				$this->item_db->update(array('order_id'=>$order),array('id'=>$id));
			}
			showmessage(L('operation_success'));
		} else {
			showmessage(L('operation_failure'));
		}
	}
	private function get_sort_tree($pid){
		$result = $this->jihe_item_db->select('','*','','order_id ASC');
		$this->tree->icon = array('&nbsp;│ ','&nbsp;├─ ','&nbsp;└─ ');
		$this->tree->nbsp = '&nbsp;';
		foreach($result as $r) {
			$r['cname'] = $r['classname'];
			$r['parentid'] = $r['pid'];
			$array[] = $r;
		}
		$str  = "<option value=\$id \$selected>\$spacer\$cname</option>";
		$this->tree->init($array);
		$sort_tree = $this->tree->get_tree(0, $str,$pid);
		return $sort_tree;
	}
}